//
//  NSCacheTool.swift
//  SwiftYC
//
//  Created by tenltrs on 2018/9/11.
//  Copyright © 2018年 Tenltrs. All rights reserved.
//

import UIKit

@objcMembers class NSCacheTool: NSObject {
    
    private var dictionary : [String : Any?] = [:]
    
    static let cache: NSCacheTool = NSCacheTool()
    class func defaultCache() -> NSCacheTool {
        return cache
    }

    override func setValue(_ value: Any?, forKey: String) {
        if value == nil {
            self.dictionary.removeValue(forKey: forKey)
        }else{
            self.dictionary[forKey] = value
        }
    }
    
    override func value(forKey: String) -> Any? {
        return self.dictionary[forKey] ?? nil
    }

    func allKeys() -> [String] {
        let keys = Array(dictionary.keys)
        return keys
    }
}
